package mo.tags.stack;

public class L2375 {

    public String smallestNumber(String pattern) {
        int n = pattern.length();
        StringBuilder sb = new StringBuilder();
        sb.append(1);
        for (int i = 0; i < n; i++) {
            char c = pattern.charAt(i);
            if (c == 'I') {
                sb.append(i + 2);
            } else {
                int cur = i;
                while (cur > 0 && sb.charAt(cur - 1) > sb.charAt(cur)) {
                    cur--;
                }
                sb.insert(cur, i + 2);
            }
        }
        return sb.toString();
    }


    public static void main(String[] args) {
        L2375 test = new L2375();
        System.out.println(test.smallestNumber("IIIDIDDD"));
    }
}
